package com.bridgeQQ.client.view.window.glue.bar
{
	import flash.display.DisplayObjectContainer;
	
	import mx.controls.Button;
	import mx.core.IWindow;
	import mx.core.windowClasses.TitleBar;
	
	public class ButtonTitleBar extends mx.core.windowClasses.TitleBar
	{
		public function ButtonTitleBar()
		{
			super();
		}
		
		private var _showButtons:Boolean = true;
		
		public function set showButtons(value:Boolean):void
		{
		    if(_showButtons != value)
		    {
		    	_showButtons = value;
		    	this.invalidateSize();
		    	this.invalidateDisplayList();
		    }	
		}
		
		public function get showButtons():Boolean
		{
			return this._showButtons;
		}
		
		public function get window():IWindow
		{
			return this.parent as IWindow;
		}
		
		protected override function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number) : void
		{
			var dd:DisplayObjectContainer = this.parent;
			if(!dd)
			{
				return;
			}
			super.updateDisplayList(unscaledWidth,unscaledHeight);
		}
		
		protected override function placeButtons(align:String, 
		    unscaledWidth:Number, unscaledHeight:Number, leftOffset:Number, rightOffset:Number, cornerOffset:Number) : void
		{
			if(showButtons)
			{
				super.placeButtons(align, unscaledWidth, unscaledHeight, leftOffset, rightOffset, cornerOffset);
				return;
			}		
			hideButton(this.minimizeButton,unscaledWidth);
			hideButton(this.maximizeButton, unscaledWidth);
			hideButton(this.closeButton,unscaledWidth);
		}
		
		private function hideButton(bt:Button, barWidth:Number)
		{
			bt.x = barWidth;
			bt.width = 0;
			bt.height = 0;
		}
	}
}